-- acc_prop
-- create by panyl
-- 技能: 赋予累计属性效果
-- 规则：
-- acc_prop(attrib,value,round)

return {
    apply = function(source, target, skillId, round, para, extra)
        -- 回合
        local effectRound = -1;

        extra = extra or {};
        local lastRound = extra.lastRound;

        if type(lastRound) == "number" then
            effectRound = round + lastRound + 1;
        elseif para[3] > 0 then
            effectRound = round + para[3] + 1;
        end

        local prop = PropM.combine(source, "magic_last", skillId);
        effectRound = PropM.apply(prop, effectRound);
        prop = PropM.combine(source, "magic_last", "assist");
        effectRound = PropM.apply(prop, effectRound);

        -- 所有技能持续时间+
        prop = PropM.combine(source, "magic_last", "all");
        effectRound = PropM.apply(prop, effectRound);

        -- 威力
        local force = para[2];
        -- 计算魔法效果加成
        local addon_rate = SkillM.calcMagicEffectAddon(source, skillId, true);
        --最终威力
        force = math.modf(force * (addon_rate + 1000)/1000);

        -- 魔力
        local magic = source:getMagic();

        -- 效果
        local v = math.modf(force * (magic + 3) / 1000);

        -- prop = { PropM.getPropId("acc_prop"), para[1], v, effectRound, };

        local condition = CombatStatusM.queryCondition(target, para[1]) or {};

        -- 可以叠加的
        condition["shield"] = (condition["shield"] or 0) + v;
        condition["shiled_type"] = para[1];
        condition["end_round"]   = effectRound;

        CombatStatusM.applyStatus(target, para[1], condition);

        -- 增加命中动作
        SkillM.getSequence(target):hit(source, target, skillId);

        -- 天赋起效，恢复n点生命值
        prop = PropM.combine(source, "cure_hp", skillId);
        if prop[3] > 0 then
            CombatM.receiveCure(source, target, prop[3]);
        end
        EventMgr.fire(event.HP_RECOVER, prop[3]);

        -- 返回作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { arr[1], tonumber(arr[2]), tonumber(arr[3] or -1), };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        -- 1. 持续回合
        desc = string.gsub(desc, "{round}", para[3]);

        -- 2. 效果
        -- 威力
        local base = para[2];
        -- 计算魔法效果加成
        local addon_rate = SkillM.calcMagicEffectAddon(source, skillId, false);
        --最终威力
        local force = math.modf(base * (addon_rate + 1000)/1000);

        -- 魔力
        local magic = source:getMagic();

        -- 效果/计算时魔力+3
        local vbase = math.modf(base * (magic + 3) / 1000);
        local vforce = math.modf(force * (magic + 3) / 1000);
        local vaddon = vforce - vbase;
        if vaddon == 0 then
            desc = string.gsub(desc, "{acc_prop}", vforce);
        else
            desc = string.gsub(desc, "{acc_prop}", vbase .. "(+" .. vaddon .. ")");
        end

        return desc;
    end,
}
